package com.ctshk.rpc.payment.dto.req.wechat;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.ctshk.common.utils.MD5Util;
import com.ctshk.rpc.payment.dto.WeChatPayConfig;
import lombok.Data;

import java.io.Serializable;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.rpc.payment.dto.req.wechat
 * @Author: hef
 * @CreateTime: 2021-05-08 13:52
 * @Description: 描述
 */
@Data
public abstract class WeChatPayCommonReq implements Serializable {
    /**
     * 方法名
     */
    private String method;
    /**
     * 商户id
     */
    @JSONField(name = "mid")
    private String mId;
    /**
     * 秒级时间戳
     */
    @JSONField(name = "stime")
    private String sTime;
    /**
     * 签名
     */
    private String sign;

    public WeChatPayCommonReq(String method, WeChatPayConfig config) {
        this.method = method;
        this.mId = config.getMId();
        long time = System.currentTimeMillis() / 1000;
        this.sTime = String.valueOf(time);
        this.sign = MD5Util.stringMd5(mId + config.getMKey() + time).toUpperCase();
    }

    /**
     * 转换JSON
     * @return
     */
    public String toJsonString(){
        return JSON.toJSONString(this);
    }

}
